home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 16
/
016.d81
/
lk.conway's life
< prev
next >
Wrap
Text File
|
2022-08-26
|
2KB
|
101 lines
0010 //////////////////////////////////
0020 // //
0030 // conway's game of life -- by //
0040 // joel ellis rea. //
0050 // //
0060 //////////////////////////////////
0070 //
0080 //
0090 get'start'pattern
0100 g:=0
0110 repeat
0120 compute'generation
0130 display'generation
0140 until peek(198)
0150 //
0160 proc get'start'pattern
0170 dim char$ of 1
0180 print "", // clear screen, upper case.
0190 poke 53280,11
0200 poke 53280,11 // brdr dk grey
0210 poke 53281,12 // bkgnd md grey
0220 poke 646,1 // cursor white
0230 print "",tab(20),
0240 repeat
0250 cursr:=peek(209)+256*peek(210)+peek(211)
0260 byte:=peek(cursr)
0270 poke cursr,87
0280 poke 198,0
0290 while not peek(198) do null
0300 char$:=key$
0310 case char$ of
0320 when "a","","A"
0330 print "",
0340 when "z","","Z"
0350 print "",
0360 when ",","","<"
0370 print "",
0380 when ".","",">"
0390 print "",
0400 when " "
0410 if byte=81 then
0420 poke cursr,32
0430 else
0440 poke cursr,81
0450 endif
0460 otherwise
0470 null
0480 endcase
0490 if char$<>" " then poke cursr,byte
0500 until char$=chr$(13)
0510 endproc get'start'pattern
0520 //
0530 proc compute'generation
0540 blackout
0550 g:+1
0560 print "generation #",g
0570 for y#:=1 to 23 do
0580 for x#:=1 to 38 do
0590 if peek(1024+y#*40+x#)=81 then neighborize(x#,y#)
0600 endfor x#
0610 endfor y#
0620 endproc compute'generation
0630 //
0640 proc display'generation
0650 for i#:=40 to 999 do
0660 case neighbors(i#) of
0670 when 0,1,4,5,6,7,8
0680 poke i#+1024,32
0690 when 2
0700 null
0710 when 3
0720 if peek(1024+i#)=32 then poke 1024+i#,81
0730 endcase
0740 endfor i#
0750 endproc display'generation
0760 //
0770 proc blackout closed
0780 for i#:=40 to 999 do poke 55296+i#,0
0790 endproc blackout
0800 //
0810 proc neighborize(x,y)
0820 if x>0 then increment(x-1,y)
0830 if x<39 then increment(x+1,y)
0840 if y>0 then increment(x,y-1)
0850 if y<24 then increment(x,y+1)
0860 if x>0 and y>0 then increment(x-1,y-1)
0870 if x>0 and y<24 then increment(x-1,y+1)
0880 if x<39 and y>0 then increment(x+1,y-1)
0890 if x<39 and y<24 then increment(x+1,y+1)
0900 endproc neighborize
0910 //
0920 func neighbors(i) closed
0930 return (peek(55296+i)) mod 16
0940 endfunc neighbors
0950 //
0960 proc increment(x,y)
0970 l:=y*40+x
0980 poke 55296+l,neighbors(l)+1
0990 endproc increment
1000 //